package com.bw.merchant.page.fragment

import android.os.Bundle
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.base.path.RouterPath
import com.bw.common.view.BaseMvvmActivity
import com.bw.common.view.BaseMvvmFragment
import com.bw.merchant.R
import com.bw.merchant.databinding.ActivityApprovalDetailBinding
import com.bw.merchant.vm.MerchantViewModel
import dagger.hilt.android.AndroidEntryPoint

@Route(path = RouterPath.PATH_APPROVAL_DETAIL_PATH)
@AndroidEntryPoint
class ApprovalDetailActivity :BaseMvvmActivity<ActivityApprovalDetailBinding>() {

    @Autowired
    @JvmField
    var iid :Int = 0
    override fun getLayoutId(): Int = R.layout.activity_approval_detail

    private val mViewModel : MerchantViewModel by viewModels()
    override fun initViews() {
        super.initViews()
        ARouter.getInstance().inject(this)
        mViewModel.getApprovalDetailData(iid)
        mDataBinding.back.setOnClickListener {
            finish()
        }
        mViewModel.mApprovalDetailSuccess.observe(this){
            if (it.status == "已审核" || it.status == "驳回"){
                mDataBinding.status.text = "已审核"
                mDataBinding.applicationNumber.text = it.applicationNumber
                mDataBinding.enterpriseName.text = it.enterpriseName
                mDataBinding.applicationTime.text = it.processingSteps[0].stepTime
                mDataBinding.peopleName.text = it.contactName
                mDataBinding.applicationCount.text = "${it.entryPersonnel}"
                mDataBinding.applicationArea.text = "${it.applicationArea}m²"
                mDataBinding.merchantTime.text = it.entryTime
                mDataBinding.entryTime.text = it.entryTime
                mDataBinding.eTime.text = it.entryTime
                mDataBinding.enterName.text = "发起申请(${it.contactName})"
                mDataBinding.lastTime.text = it.entryTime
                if (it.status == "已审核"){
                    mDataBinding.text2.text = "审核通过"
                }else if (it.status == "驳回"){
                    mDataBinding.text2.text = "已驳回"
                    mDataBinding.square2.setBackgroundResource(R.drawable.ind_select_red)
                    mDataBinding.circle23.setBackgroundResource(R.drawable.circle_status_red)
                }
            }else{
                mDataBinding.status.text = "待审核"
                mDataBinding.applicationNumber.text = it.applicationNumber
                mDataBinding.enterpriseName.text = it.enterpriseName
                mDataBinding.applicationTime.text = it.processingSteps[0].stepTime
                mDataBinding.peopleName.text = it.contactName
                mDataBinding.applicationCount.text = "${it.entryPersonnel}"
                mDataBinding.applicationArea.text = "${it.applicationArea}m²"
                mDataBinding.merchantTime.text = it.entryTime
                mDataBinding.entryTime.text = it.entryTime
                mDataBinding.eTime.text = it.entryTime
                mDataBinding.enterName.text = "发起申请(${it.contactName})"

                if (it.status == "新建"){
                    mDataBinding.text2.text = "待审核"
                    mDataBinding.square2.setBackgroundResource(R.drawable.ind_select_no)
                    mDataBinding.circle23.setBackgroundResource(R.drawable.circle_status_no)
                }
            }


//            if (it.processingSteps[1].id != null){




//            }else{
//                mDataBinding.text2.visibility = View.GONE
//                mDataBinding.square2.visibility = View.GONE
//                mDataBinding.circle23.visibility = View.GONE
//            }
        }
    }



}